<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta charset="UTF-8">
    <title>订单详情</title>

    <header th:replace="header::html"></header>
</head>

<body>

<div class="demoTable">
    <div class="layui-fluid">
        <div class="layui-row  layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">

                    <div class="layui-card-body ">
                        <table class="layui-hide" id="orderTable" lay-filter="orderTable" ></table>
                    </div>
                    <div class="layui-card-body ">
                        <script type="text/html" id="bar">
                            <a class="layui-btn layui-btn-xs" lay-event="checkDetails">查看详情</a>

                            {{#  if(d.tips1 == "进行中"){ }}
                        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="payWork" >确认发货</a>
                        {{#  }

                            else { }}
                            {{#  }}}
                    </script>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
</body>



<script>



	layui.use('table', function () {
		var table = layui.table;

		//第一个实例
		table.render({
			elem: '#orderTable'
			, url: '/api-front/serviceproviders/list' //数据接口
			, page: true //开启分页
			, limits: [5]
			, limit: 5
			, cols: [
				[ //表头
					{title:'ID',type:'numbers', align: 'center',width:'5%'}
					, {field: 'oid', title: '订单ID', align: 'center',hide:true}
					, {field: 'needid', title: '需求ID', align: 'center',hide:true}
					, {field: 'workid', title: '作品ID', align: 'center',hide:true}
					, {field: 'tips3', title: '时间',  align: 'center',hide:true}
					, {field: 'tips1', title: '订单状态',  align: 'center',width:'13%'}
					, {field: 'tips2', title: '订单金额', align: 'center',width:'13%'}
					, {field: 'ostarttime', title: '订单生成时间', align: 'center',width:'15%'}
					, {field: 'oendtime', title: '结束时间', align: 'center',width:'15%'}
					, {field: 'orealtime', title: '订单工期', align: 'center',width:'11%'}
					, {toolbar: "#bar", title: '操作', width: "25%",align: 'center',width:'28%'}

				]
			]
		});
		table.on('tool(orderTable)', function (obj){
			var data = obj.data;//获取点击行数据
			if (obj.event ==='checkDetails') {
				// alert("66666");
				var oid2 = data.oid;
				xadmin.open('查看订单详情页面', '/api-front/serviceproviders/orderForm/?oid=' + oid2);
			}else if(obj.event ==='payWork'){
				//alert("走发货页面");
				var nid1=data.needid;
				var oid1=data.oid;
				$.ajax({
					url: "/api-front/serviceproviders/delivery",
					type: "GET",
					data: {nid: nid1,oid:oid1},
					dataType: 'text',
					success: function (msg) {
						if (msg === "yes") {
							layer.alert("交货成功", {icon: 1}, function (index1) {
								layer.close(index1);
								table.reload('orderTable');
							});

						} else {
							layer.alert("交货失败，请稍后操作", {icon: 1}, function (index1) {
								layer.close(index1);
								table.reload('orderTable');
							});

						}
					}
				});

            }


		});






		$('.demoTable .layui-btn').on('click', function () {
			//alert("6666");
				var type = $(this).data('type');
				if (type == 'reload') {
					//执行重载
					table.reload('orderTable', {
						page: {
							curr: 1 //重新从第 1 页开始
						}
						, where: {
							startDate: $("#startDate").val(),
							endDate: $("#endDate").val()
						}
					});
				}


		});


	});






</script>
</html>